import {Base} from "../../utils/base.js";

class Model extends Base{
  constructor(){
    super();
  }

  /**
   * 获取分类
   * @param {*} success 
   * @param {*} fail 
   */
  getCategory(success,fail){
    this.request({
      url: '/get_integral_category',
      success: (res)=>{
        success&&success(res);
      },
      fail:(res)=>{
        fail&&fail(res);
      }
    });
  }

  /**
   * 根据分类获取商品数据
   * @param {*} cid 
   * @param {*} page
   * @param {*} success 
   * @param {*} fail 
   */
  getCategoryShopList(cid,page,success,fail){
    this.request({
      url: '/get_category_integral_list/'+cid,
      data:{
        page
      },
      success: (res)=>{
        success&&success(res);
      },
      fail:(res)=>{
        fail&&fail(res);
      }
    });
  } 

  // 获取积分商城详情
  getIntegralInfo(id,callback){
    this.request({
      url: '/get_integral_info/'+id,
      success: function (res) {
        callback && callback(res)
      },
      fail: function (res) {
        callback && callback(res)
      }
    })
  }

  /**
   * 获取下单购买信息
   * @param {*} id 
   * @param {*} callback 
   */
  getIntegralPayDetail(id, callback){
    this.request({
      url: '/get_integral_pay_detail/' + id,
      success: function (res) {
        callback && callback(res)
      },
      fail: function (res) {
        callback && callback(res)
      }
    })
  }

  /**
   * 根据订单获取订单详细信息
   * @param {*} orderNo 
   * @param {*} success 
   * @param {*} fail 
   */
  getIntegralOrderInfo(orderNo,success,fail){
    this.request({
      url: '/get_integral_order_info/' + orderNo,
      success: function (res) {
        success && success(res)
      },
      fail: function (res) {
        fail && fail(res)
      }
    })
  }


  // 提交订单
  setIntegralOrder(data,callback){
    this.request({
      url: '/exchange_shop',
      type:'POST',
      data:data,
      success: function (res) {
        callback && callback(res)
      },
      fail: function (res) {
        callback && callback(res)
      }
    })
  }

  // 获取积分记录
  getRecords(callback) {
    this.request({
      url: '/get_records',
      success: function (res) {
        callback && callback(res)
      }
    })
  }

  // 获取我的兑换列表
  getExchangeList(callback) {
    this.request({
      url: '/get_exchange_list',
      success: function (res) {
        callback && callback(res)
      }
    })
  }
}
export {Model}